<?PHP
//索引换名为techId格式
  $result[] =  
    array(
      'tech_id' => '456',
      'tech_order' => '36',
      'tech_parent' => '-1',
      'tech_column' => '0',
      'tech_type' => '1',
      'tech_desc' => '',
      'tech_name' => 'zzz',
      'tech_show' => '0',
      );
    $result[] = 
      array('tech_id' => '457',
      'tech_order' => '37',
      'tech_parent' => '-1',
      'tech_column' => '0',
      'tech_type' => '1',
      'tech_desc' => '',
      'tech_name' => 'ccc',
      'tech_show' => '0',
      );
      // var_dump($result);die();
foreach($result as $k=>$v){
    unset($result[$k]);
    foreach($v as $key=>$val){
        $str = preg_replace_callback('/([-_]+([a-z]{1}))/i',function($matches){
            return strtoupper($matches[2]);
        },$key);
        unset($v[$key]);
        $result[$k][$str] = $val;
    }
}
echo '<pre>';
var_dump($result);

//微信随机红包  2:2:1红包
$min = 0.87;
$max = 8.7;
$apart = 3;
$between = ($max-$min)/$apart;
$arr = array('0' => array('left' => $min, 'right' => $min+$between));var_dump($between);
for($i=1;$i<$apart;$i++){
    $arr[$i]['left'] = $arr[$i-1]['right']+0.01;
    $arr[$i]['right'] = $arr[$i-1]['right'] + $between;
}
//1-5随机数对3取余等于2,1,0的概率比为2:2:1
$rx = 1;
$ry = 5;
$divisor = 3;
$x_figure = rand(1,5)%$divisor;
switch ($x_figure) {
    case '2':
        //数据库执行红包语句，传递参数$arr[0]
        break;
    case '1':
        //数据库执行红包语句，传递参数$arr[1]
        break;
    case '0':
        //数据库执行红包语句，传递参数$arr[2]
        break;
    
    default:
        break;
}


//微信红包优化算法   产生n1:n2:n3:...:nm红包
$inputs = "1:2:2:1";

$rate = explode(':',$inputs); 
$min = 0.87;
$max = 8.7;
$apart = count($rate);
$between = round(($max-$min)/$apart,2);
$arr = array('0' => array('left' => $min, 'right' => $min+$between));
for($i=1;$i<$apart;$i++){
    $arr[$i]['left'] = $arr[$i-1]['right']+0.01;
    $arr[$i]['right'] = $arr[$i-1]['right'] + $between;
}
$rate_arr = array();
$num = 1;
foreach ($rate as $key => $value) {
    $temp = $value;
    while ($temp > 0) {
        array_push($rate_arr, $num);
        $temp--;
    }
    $num++;
}

$x_index = array_rand($rate_arr, 1);
$x_figure = $rate_arr[$x_index];
for($i=1;$i<=$apart;$i++){
    var_dump($i);
    if($x_figure==$i){
        //数据库执行红包语句，传递参数$arr[$i-1]
    }
}

echo '</br>';
var_dump($x_figure);
echo '<pre>';
var_dump($rate_arr);die();


//获取最大的连续和
function max_sum_array($arr)
{
    $currSum = 0;
    $maxSum = 0;//数组元素全为负的情况，返回最大数
    $sum = 0;
    $n = count($arr);

    for ($i = 0; $i < $n; $i++) { 
        if($sum<=$currSum){
          $sum = $currSum;
        }
        if ($currSum >= 0) {
            $currSum += $arr[$i];
            
        } else {
            $currSum = $arr[$i];
        }
        // echo $currSum;
        // echo '<br />';
    }

    if($currSum < $sum){
        $currSum = $sum;
    }
    if ($currSum > $maxSum) {
        $maxSum = $currSum;
    }

    return $maxSum;
}
$arr=array(1, -2, 3, 10, -4, 7, 2, -5,100,-10,11);
var_dump(max_sum_array($arr));


//只匹配>0数字/英文逗号（正则）
function my_preg($str){
        if(preg_match("/^[,1-9]+$/",$str))
        {
                return $str;
        }
        else{
                return false;
        }
 
}
var_dump(gt0('123,'));


//自动日志,仅记录对数据库有影响的操作，不记录的操作除外
  public function autoLog(){
    if( strstr(strtoupper(ACTION_NAME),"HANDLE")&&!in_array(strtoupper(ACTION_NAME),explode(',',strtoupper(C('NOT_AUTOLOG_ACTION'))))){
        $sysName = strtoupper(substr(__GROUP__, 1));
        $nodes=cache('nodes');
        if(!$nodes){
          $nodelist = D("Node")->select();
          foreach($nodelist as $key=>$value){
            $nodes[strtoupper($nodelist[$key]['name'])]=$nodelist[$key]['title'];
          }
          cache('nodes',$nodes,60);//缓存一小时
        }
        $log['VAL_LOGINID']=$_SESSION['_USER_INFO']['account'];
        $log['VAL_TIME']=date("Y-m-d H:i:s");
        $log['VAL_MODEL_RESOURCE']=$nodes[$sysName]."--".$nodes[strtoupper(MODULE_NAME)];
        $log['VAL_ACTION']=$nodes[strtoupper(ACTION_NAME)];
        $inputs['GET']=$_GET;
        $inputs['POST']=$_POST;
        $log['VAL_OBJECT']=json_encode($inputs);
        $log['VAL_IP']=get_client_ip();
        $sysName = substr(__GROUP__, 1);
        $log['VAL_COMMAND_NAME']=strtolower($sysName).'/'.strtolower(MODULE_NAME).'/'.strtolower(ACTION_NAME);
        //dump($log);exit;
        $actionLogMOdel=D("ActionLog");
        
        $b = $actionLogMOdel->add($log);
      }
  }

  





